21. The Wider World of Testing

The Wider World of Testing

Instrumented Unit Tests

We just covered User Interface Tests which are a type of Instrumented Unit Tests. These are tests that must be run on an Android device or emulator because they depend on the Android framework.

For example, in a calculator app, checking that the correct operation triggers when a user clicks on the UI requires the Android framework.

Instrumented tests run using the AndroidJUnitRunner which controls launching the app and running UI tests on it.

As we've seen, Instrumented Tests live under* module-name/src/androidTest/java/*

Local Unit Tests

There are other tests such as Local Unit Tests which you may have seen included in projects such as the Sunshine app. Local Unit Tests are Unit tests that are only run on the local Java Virtual Machine and don’t necessarily depend on the Android framework.

For example, say you have a class in a Calculator Android project that is used for the calculation operations. Testing these calculation methods is not dependent on the Android framework.

Instead, you’ll use the JUnit testing framework for Java to just test that local test.

Local Unit tests live in the module-name/src/test/java/ of the project folders.

JUnit

JUnit is a framework used to test discrete pieces of code (usually methods).

Android provides JUnit testing support via the AndroidJUnit Test Runner.

Android Testing Support Library

Espresso is just one test automation tool provided by the Android Testing Support Library. This Library also includes AndroidJUnitRunner and UI Automator.

  • AndroidJUnit - A test runner that runs JUnit style tests on Android devices. When used in Espresso tests, it controls launching the app and running UI tests.
  • Espresso - Framework for functional UI Testing
  • UI Automator - Framework for cross-app functional UI testing between the system and installed apps

Learn More